package com.chhh.cranelease.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
public class InterceptorsMvc implements WebMvcConfigurer {

    @Autowired
    private PrereadConfig config;

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("login");
        registry.addViewController("/index.html").setViewName("login");
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/error").setViewName("error");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(new LoginHandlerInterrupt())
            .addPathPatterns("/car/**")
            .addPathPatterns("/driver/**")
            .addPathPatterns("/carlog/**")
            .addPathPatterns("/parts/**")
            .addPathPatterns("/finace/**")
            .addPathPatterns("/repair/**")
            .addPathPatterns("/peoplelog/**");
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /*uploadFile：映射成的相对路径的位置
        图片存放的绝对路径
        如果img或其他的标签，资源为/uploadFile/**，自动去绝对路径去读取*/
        registry.addResourceHandler("/upload/**").addResourceLocations("file:"+config.getUploadpath());
    }

}
